/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.managedbean;

import javax.faces.bean.ManagedBean;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.bean.RequestScoped;
import org.primefaces.push.PushContext;
import org.primefaces.push.PushContextFactory;

/**
 *
 * @author Muharrem Tigdemir
 */
@ManagedBean
@RequestScoped

public class GrowlBean {

    private String text;
    private String header;

    public GrowlBean(String text, String header) {
        this.text = text;
        this.header = header;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public void save(ActionEvent actionEvent) {
        FacesContext context = FacesContext.getCurrentInstance();

        context.addMessage(null, new FacesMessage(header, text));
    }

    public void send() {
        PushContext pushContext = PushContextFactory.getDefault().getPushContext();
        pushContext.push("/notifications", new FacesMessage(header, text));
    }
}
